package com.hou.jvm;

public class ReferenceCountTest {
    public Object instance;
    private byte[] num=new byte[2*1024*1024]; //2M大小,方便查看内存是否回收
    public static void main(String[] args) {
        ReferenceCountTest referenceCountTest01 = new ReferenceCountTest();
        ReferenceCountTest referenceCountTest02 = new ReferenceCountTest();
        referenceCountTest01.instance=referenceCountTest02; //循环引用
        referenceCountTest02.instance=referenceCountTest01;
        referenceCountTest01=null; //为空后已无法访问,但是引用计数也不回收
        referenceCountTest02=null;
        System.gc();
    }
}
